import { useUserStore } from '@/stores/user';

// 检查用户是否已登录
export const isAuthenticated = (): boolean => {
  const userStore = useUserStore();
  return userStore.isLoggedIn;
};

// 检查用户是否有特定权限
export const hasPermission = (permission: string): boolean => {
  const userStore = useUserStore();
  return userStore.hasPermission(permission);
};

// 检查用户是否有任一权限
export const hasAnyPermission = (permissions: string[]): boolean => {
  const userStore = useUserStore();
  return permissions.some(permission => userStore.hasPermission(permission));
};

// 检查用户是否有所有权限
export const hasAllPermissions = (permissions: string[]): boolean => {
  const userStore = useUserStore();
  return permissions.every(permission => userStore.hasPermission(permission));
};

// 登出函数
export const logout = (): void => {
  const userStore = useUserStore();
  userStore.clearUserInfo();
  window.location.href = '/login';
};